<?php 

class Silk_Pms_Model_Mysql4_Gift_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
	public function _construct()
	{
		parent::_construct();
        $this->_init('pms/gift');
	}

	public function addWebsiteFilter($websiteId = null)
	{
		if(is_null($websiteId))
		{
			$websiteId = Mage::app()->getWebsite()->getId();
		}
		$this->getSelect()->where('website_id=?', $websiteId);
		return $this;
	}

	public function addDateFilter($now = null)
	{
		if (is_null($now)) {
			$now = Mage::getModel('core/date')->date('Y-m-d');
		}
		$this->getSelect()
			->where('from_date is null or from_date <= ?', $now)
			->where('to_date is null or to_date >= ?', $now);
		return $this;
	}

	public function addStockFilter()
	{
		$this->getSelect()->where('used_qty <= gift_qty');
		return $this;
	}

	public function addValidateFilter()
	{
		$this->addFieldToFilter('status',array('eq'=>1));
		$this->addFieldToFilter('discount_step', array('gt'=>0));
		$this->addFieldToFilter('discount_qty', array('gt'=>0));
		$this->addWebsiteFilter();
		$this->addDateFilter();
		return $this;
	}
}